package net.lastcoder.ifserver;

import net.lastcoder.ifserver.module.ModuleManager;
import net.lastcoder.ifserver.plugin.Plugin;
import net.lastcoder.ifserver.plugin.PluginManager;
import net.lastcoder.ifserver.terminate.TerminateConnectionAcceptor;
import net.lastcoder.ifserver.terminate.TerminateManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 * auth: WenYF
 * date: 2017/2/6
 */
public class ConsolePlugin implements Plugin {
    private static final Logger Log = LoggerFactory.getLogger(ConsolePlugin.class);
    private TerminateConnectionAcceptor terminateAccrptor;

    @Override
    public void initializePlugin(PluginManager manager, File pluginDirectory) {
        terminateAccrptor = new TerminateConnectionAcceptor();
        terminateAccrptor.start();

        TerminateManager terminateManager = TerminateManager.getInstance();
        ModuleManager.getInstance().addModule(terminateManager);
    }

    @Override
    public void destroyPlugin() {
        ModuleManager.getInstance().removeModule(TerminateManager.getInstance().getName());

        TerminateManager.getInstance().destroy();

        terminateAccrptor.stop();
    }

}
